﻿@model Citi.GocAttributes.WebUI.Models.GocOptionModel
@if (Model.Gocs == null || !Model.Gocs.Any())
{
    <text>No GOC was found.</text>
    return;
}
<script type="text/javascript">
    $(function () {
        $("#ShowManagedSegments").change(function () {
            $(".managedSegmentLevels").toggle();
        });

        $("#ShowFunctions").change(function () {
            $(".functionLevels").toggle();
        });

        $("#ShowOTFunctions").change(function () {
            $(".otFunctions").toggle();
        });

        $("a").each(function (index, item) {
            if (item.href.indexOf("#") > 0) {
                item.click(function () {
                    $("#filter").click();
                });
            }
        });
    });
</script>
@Html.CheckBox("ShowManagedSegments")Show all Managed Segment Levels
@Html.CheckBox("ShowFunctions")Show all Functions Levels
@Html.CheckBox("ShowOTFunctions")Show O&T Functions
<br />
<br />
<table class="table table-bordered table-striped">
    <thead>
        <tr>
            @if (Model.Exception)
            {
                <th>
                </th>
            }
            <th>
                Goc Attributes
            </th>
            <th>
                Long Description
            </th>
            <th>
                Corp Code
            </th>
            <th>
                Expense Code
            </th>
            @*<th>
                Status
            </th>*@
            <th>
                SID
            </th>
            <th>
                Local Cost Code
            </th>
            <th>
                Manager
            </th>
            <th>
                FrsBu
            </th>
            <th>
                FrsOu
            </th>
            <th>
                LVID
            </th>
            <th>
                Function
            </th>
            <th>
                Managed Segment
            </th>
            @{
                var functionsCount = Model.Gocs.Max(x => x.Function.TreeLevel);
                var managedSegmentCount = Model.Gocs.Max(x => x.ManagedSegment.TreeLevel);

                for (int i = 0; i < managedSegmentCount; i++)
                {
                <th class="managedSegmentLevels" style="display: none">
                    Managed Segment L@(i + 1)
                </th>
                }

                for (int i = 0; i < functionsCount; i++)
                {
                <th class="functionLevels" style="display: none">
                    Function L@(i + 1)
                </th>
                }
            }
            <th>
                Managed Geography
            </th>
            <th>
                Inserted On
            </th>
            <th>
                Rule
            </th>
            @foreach (int item in Enum.GetValues(typeof(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType)))
            {
                Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType enumValue;
                Enum.TryParse<Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType>(item.ToString(), out enumValue);
    
                <th class="otFunctions" style="display: none">
                    @enumValue.GetDescription()
                </th>
            }
            <th>
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.Gocs)
        {
            <tr>
                @if (Model.Exception && !item.GocRules.Any())
                {
                    <td>
                        <input type="checkbox" class="gocCheck" id="@string.Concat("applyRule", item.Id)"/>
                    </td>
                }
                <td>
                    @Html.DisplayFor(modelItem => item.GocAttribute)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LongDescription)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CorpCode)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ExpenseCode)
                </td>
                @*<td>
                    @Html.DisplayFor(modelItem => item.Status)
                </td>*@
                <td>
                    @Html.DisplayFor(modelItem => item.Sid.Description)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LocalCostCode)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Manager)
                </td>
                <td>
                    @string.Format("{0} - {1}", item.FrsBu.Code, item.FrsBu.Description)
                </td>
                <td>
                    @string.Format("{0} - {1}", item.FrsOu.Code, item.FrsOu.Description)
                </td>
                <td>
                    @string.Format("{0} - {1}", item.LegalVehicle.Code, item.LegalVehicle.Description)
                </td>
                <td>
                    @string.Format("{0} - {1}", item.Function.Code, item.Function.Description)
                </td>
                <td>
                    @string.Format("{0} - {1}", item.ManagedSegment.Code, item.ManagedSegment.Description)
                </td>
                <td>
                    @string.Format("{0} - {1}", item.Country.Abbreviation, item.Country.Description)
                </td>
                @for (int i = 0; i < managedSegmentCount; i++)
                {
                    <td class="managedSegmentLevels" style="display: none">
                        @if (i < item.ManagedSegmentLevels.Count())
                        {
                            <span id="@string.Concat("ManagedSegmentLevels", i + 1, "-", item.Id)">@item.ManagedSegmentLevels[i]</span>
                        }
                        else
                        {
                            <text>-</text>
                        }
                    </td>
                }
                @for (int i = 0; i < functionsCount; i++)
                {
                    <td class="functionLevels" style="display: none">
                        @if (i < item.FunctionsLevels.Count())
                        {
                            <span id="@string.Concat("FunctionLegalVehicle", i + 1, "-", item.Id)">@item.FunctionsLevels[i]</span>
                        }
                        else
                        {
                            <text>-</text>
                        }
                    </td>
                }
                <td>
                    @item.ReferenceDate.ToString("MMM/yy")
                </td>
                <td>
                    @if (Model.Exception && !item.GocRules.Any())
                    {
                        <a href="#" onclick="applyIndividualRule('@item.Id')">Apply</a>
                    }
                    else if (item.GocRules.Any())
                    {
                        @item.GocRules.Last().Rule.Name
                        @Ajax.ActionLink("(Remove)", "RemoveRule", new { id = item.Id },
                                                  new AjaxOptions { UpdateTargetId = "gocsList", Confirm = "Are you sure?" })
                    }
                </td>
                @foreach (int type in Enum.GetValues(typeof(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType)))
                {
                    <td class="otFunctions" style="display: none">
                        @item.GetRuleResult((Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType)type)
                    </td>
                }
                @* <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.Business)
                </td>
                <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.Business1)
                </td>
                <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.Area)
                </td>
                <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.DeckRegional)
                </td>
                <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.DeckRegional1)
                </td>
                <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.Local)
                </td>
                <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.FPAManager)
                </td>
                <td class="otFunctions" style="display: none">
                    @item.GetRuleResult(Citi.GocAttributes.Domain.DatabaseEnums.TypeResultType.FPAAnalyst)
                </td>*@
                @*<td>@item.OUC
                </td>
                <td>@(item.Corinth ? "Corinth" : "-")
                </td>
                <td>@item.Project
                </td>*@
                <td>@Html.ActionLink("Edit", "Edit", new { id = item.Id })
                </td>
            </tr>
        }
    </tbody>
</table>
@Html.Partial("~/Views/PartialView/Pager.cshtml", new Citi.GocAttributes.WebUI.Models.PagerModel { PagedList = Model.Gocs, AjaxOptions = new AjaxOptions { UpdateTargetId = "gocsList" } })
